import request from '@/utils/request'

// 采购入库单相关API

/**
 * 根据采购入库单号查询入库单信息
 * 注意：此接口实际是根据入库单编号查询，如果采购订单号就是入库单编号则可以使用
 * @param {string} recptCode - 采购入库单好
 * @returns {Promise} API响应
 */
export function getItemRecptByRecptCode(recptCode) {
  return request({
    url: '/mobile/wm/itemrecpt/getByCode',
    method: 'get',
    params: { recptCode: recptCode }
  })
}

/**
 * 根据采购订单id刷新行信息
 * @param {Object} recptId
 */
export function getItemRecptByRecptId(recptId) {
  return request({
    url: '/mobile/wm/itemrecpt/getByRecptId',
    method: 'get',
    params: { recptId: recptId }
  })
}

// 提交入库单
export function submitItemRecpt(recptId) {
  return request({
    url: '/mobile/wm/itemrecpt/submit',
    method: 'post',
    params: { recptId }
  })
}

// 执行入库单
export function executeItemRecpt(recptId){
  return request({
    url: '/mes/wm/itemrecpt/' + recptId,
    method: 'put'
  })
}

/**
 * 根据入库单行ID查询入库单明细
 * @param {number} lineId - 入库单行ID
 * @returns {Promise} API响应
 */
export function getItemRecptDetail(lineId) {
  return request({
    url: '/mobile/wm/itemrecpt/getDetail',
    method: 'get',
    params: { lineId }
  })
}

//-------------------明细接口--------------------------
// 新增物料入库单明细
export function addItemreceptdetail(data) {
  return request({
    url: '/mes/wm/itemreceptdetail',
    method: 'post',
    data: data
  })
}

// 修改物料入库单明细
export function updateItemreceptdetail(data) {
  return request({
    url: '/mes/wm/itemreceptdetail',
    method: 'put',
    data: data
  })
}

// 删除物料入库单明细
export function delItemreceptdetail(detailId) {
  return request({
    url: '/mes/wm/itemreceptdetail/' + detailId,
    method: 'delete'
  })
}

// 根据状态查询入库单列表
export function getItemRecptListByStatus(pageNum, pageSize, status) {
  return request({
    url: '/mobile/wm/itemrecpt/listForStatus',
    method: 'get',
    params: { 
      pageNum: pageNum,
      pageSize: pageSize,
      status: status
    }
  })
}